package com.yanqu.road.logic.pb;

import com.yanqu.road.entity.player.UserBuilding;
import com.yanqu.road.pb.building.BuildingProto;

import java.util.List;

public class BuildingPb {

	public static BuildingProto.BuildingTempMsg.Builder parseBuildingTempMsg(UserBuilding building) {
		if(null == building){
			return null;
		}
		BuildingProto.BuildingTempMsg.Builder msg = BuildingProto.BuildingTempMsg.newBuilder();
		msg.setBuildingId(building.getBuildingId());
		msg.setLevel(building.getLevel());
		msg.setStaffCount(building.getStaffCount());
		for (int patronsId : building.getPatronsIdList()) {
			msg.addPatronsIdList(patronsId);
		}
		return msg;
	}

	public static BuildingProto.BuildingListMsg.Builder parseBuildingListMsg(List<UserBuilding> buildingList) {
		BuildingProto.BuildingListMsg.Builder msgList = BuildingProto.BuildingListMsg.newBuilder();
		if(null != buildingList) {
			for (UserBuilding userBuilding : buildingList) {
				BuildingProto.BuildingTempMsg.Builder msg = parseBuildingTempMsg(userBuilding);
				if (null != msg) {
					msgList.addBuildingList(msg);
				}
			}
		}
		return msgList;
	}
}
